// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
@property(cc.Node)
 PT:cc.Node=null;
zk:boolean=false;
@property(Number)
c:number=1
zzk(){
   
   
   this.moveX(this.PT,360*this.c,80)
 //  this.node.parent.scale*=1.2
this.zk=true;
cc.tween(this.node.parent).to(0.2, { scaleX: this.node.parent.scaleX*1.4 }).start();
cc.tween(this.node.parent).to(0.2, { scaleY: this.node.parent.scaleY*1.4 }).start();

}



zzb(){ 
    this.moveX(this.PT,-360*this.c,80);
    
   // this.node.parent.scale/=1.2
   cc.tween(this.node.parent).to(0.2, { scaleX: this.node.parent.scaleX/=(1.4)}).start();
   cc.tween(this.node.parent).to(0.2, { scaleY: this.node.parent.scaleY/=(1.4)}).start();
    this.zk=false;}


DZ(){
if(this.zk){this.zzb()}else{this.zzk()}



}

moveX(sprite:cc.Node, distance:number, duration:number) {
    const fps = 30;
    const totalFrames = Math.ceil(duration / 1000 * fps);
    const step = distance / totalFrames;
    let currentFrame = 0;
    
    const interval = setInterval(() => {
        sprite.x += step;
        currentFrame++;
        
        if (currentFrame === totalFrames) {
            clearInterval(interval);
            console.log("移动完成");
            console.log("当前位置：", sprite);
        }
    }, 1000 / fps);
}


}
